#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;


class Solution{
public:
	void merge(int A[], int m, int B[], int n) {
		int idxa = m - 1;
		int idxb = n - 1;
		for (int i = 0; i < m + n; ++i){
			// compare idxa and idxb
			if (idxb < 0) return;
			if (idxa < 0){
				A[m + n - i - 1] = B[idxb];
				--idxb;
				continue;
			}
			if (A[idxa] > B[idxb]){
				A[m + n - i - 1] = A[idxa];
				--idxa;
			}
			else{
				A[m + n - i - 1] = B[idxb];
				--idxb;
			}
		}
	}
};



int main(int argc, char** argv){
	int A[9]{-1, 0, 0, 3, 3, 3};
	int B[3]{1, 2, 2};
	Solution().merge(A, 6, B, 3);
	for (int i = 0; i < 9; ++i)
		cout << A[i] << endl;
	return 0;
}